package plgutils

import (
	"dgo/goutils/gis"
	"gitee.com/ymofen/gobase"
)

type GisRegionItem struct {
	Owner     *GisRegionPlg
	Id        string
	sn        int
	typelst   string // [corsplus][corsplus-childtype]
	regionstr string
	region    *gis.Polygon
	state     int8
	attrstr   string
	attr      gobase.StrMap
	warn      string
	loadflag  int8
}

func (this *GisRegionPlg) checkGetItem(id string) *GisRegionItem {
	rval := this.regionlst.LoadOrStoreFunc(id, func() interface{} {
		rval := &GisRegionItem{Id: id, Owner: this}
		return rval
	}, nil).(*GisRegionItem)
	return rval
}

func (this *GisRegionItem) setRegionStr(s string) bool {
	if this.regionstr != s {
		this.regionstr = s
		if len(s) == 0 {
			this.region = nil
			return true
		}
		reg := gis.NewPolygon()
		reg.ParseSimpleWKT_XY(s)
		if reg.IsValid() {
			this.region = reg
		} else {
			this.Owner.LogWarnMessage(1, "[%s]区域数据非法！", this.Id)
		}
		return true
	}
	return false
}
